#include <bmpreader.h>
#include <stdio.h>
#include <stdlib.h>
#include <codelets.hpp>
#include <Timer.h>

// CPU Version

int main(int argc, char ** argv)
{
    if (argc < 2)
    {
        printf("usage: %s filename\n", argv[0]);
        exit(1);
    }

	Timer t;
	int w, h;
	bmpreader image(argv[1]);
	image.readBMP();				// read the BMP file
	image.writeBMP("before.bmp");	// write the before picture (same file)
	
	w = image.getWidth();
	h = image.getHeight();
    float caoKernel[9] = { -1/6.0f, -4.0f/6.0, -1.0/6.0f,
                            -4/6.0f, 26/6.0f, -4/6.0f,
                            -1/6.0f, -4/6.0f, -1/6.0f };

	BYTE *input		= (BYTE *) image.getImageData();
	BYTE *output	= (BYTE *) malloc (sizeof(BYTE)*w*h);
	memcpy(output, input, sizeof(BYTE)*w*h);

	t.start();
	convolve2D(w, h, input, output, caoKernel);
	t.stop();

	image.setImageData(output, sizeof(BYTE)*w*h);
	image.writeBMP("after.bmp");

	printf("Total Time: %f ms\n", t.getElapsedTimeInMilliSec());
	free (output);
}



